/*
 * @Author: qin
 * @Date:   2018-08-28
 * +----------------------------------------------------------------------
 * | admin [ 后台管理系统公共配置信息 ]
 * | 建设单位未报审列表页面脚本
 * +----------------------------------------------------------------------
 */
layui.define(['jquery', 'bluebird', 'element', 'form', 'configure', 'configureCom', 'apply'], function (exports) {
    var element = layui.element;
    var $ = layui.$;
    var form = layui.form;
    var table = layui.table;
    var configure = layui.configure;
    var configureCom = layui.configureCom;

    var baoshen = function (singleProjectId, mainProjectId) {//报审
        var title = '报审';
        var _url = configure.REPORT_MASTERIA_EDIT_HTML.replace('{singleProjectId}', singleProjectId).replace('{type}', 1010) + '&mainProjectId=' + mainProjectId;
        configureCom.klmyPop([_url, title, '报审'], false, false, function (layero, index) {
            window.saveForm = function (_data) {
                configureCom.putDataAjax(configure.APPLY_CONFIRM_HTTP, _data).then(function (res) {
                    configureCom.loadOff();
                    top.layer.msg('报审成功');
                    if (res.code === 1) {
                        if (configureCom.GetQueryString('addPadding')) {
                            configureCom.tableReload();
                        } else {
                            parent.refreshIframe();
                        }
                    } else {
                        top.layer.msg(res.msg);
                    }
                    top.layer.close(index);
                });
            };
        });
    };

    var unReportedApply = {
        data: {
            searchData: {}
        },
        eventBind: function () {
            //项目 操作
            table.on('tool(klmyTable)', function (obj) {
                var singleProjectId = obj.data.id;
                var kcBdId = '';
                var sjBdId = '';
                $.each(obj.data.kcSjdwMsgDtos, function (index, item) {
                    if (item.projBdstType == '1010') {
                        kcBdId = item.projBdstId || '';
                    }
                    if (item.projBdstType == '1020') {
                        sjBdId = item.projBdstId || '';
                    }
                });
                var mainProjectId = obj.data.mainProjectId;
                if (obj.event === 'detail') {//查看详情
                    var url = configure.ALL_COMMON_DETAIL + '?singleProjectId=' + singleProjectId + '&kcBdId=' + kcBdId + '&sjBdId=' + sjBdId + '&by=ChengGuoWbs';
                    configureCom.klmyPop([url, '查看成果']);
                } else if (obj.event === 'confirm') {//报审
                    baoshen(singleProjectId, mainProjectId);
                }
            });
            configureCom.tableSearch();
        }
    };
    exports('unReportedApply', unReportedApply);
});